package com.school.manager.interfaces;

import com.school.manager.entity.ResponseEntity;

import cn.hutool.core.util.StrUtil;

/**
 * description：请求枚举接口
 * date：2021/2/53:13 下午
 */

public interface IResponseEnum extends IMyEnum {

    default ResponseEntity createEntity(Object data) {
        return new ResponseEntity(this.getCode(), this.getMessage(), data, System.currentTimeMillis());
    }

    default ResponseEntity createEntity(String message) {
        return new ResponseEntity(this.getCode(), StrUtil.isNotEmpty(message) ? message : this.getMessage(), null, System.currentTimeMillis());
    }

    /**
     * 成功返回
     *
     * @param data
     * @return
     */
    default ResponseEntity success(Object data) {
        return createEntity(data);
    }

    /**
     * 成功返回
     *
     * @return
     */
    default ResponseEntity success() {
        return createEntity(null);
    }

    /**
     * 失败返回
     *
     * @param message
     * @return
     */
    default ResponseEntity failse(String message) {
        return createEntity(message);
    }
}
